﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using models;
using Models;

namespace yuejilalala
{
    public partial class comremark : System.Web.UI.Page
    {
        
        ComremarkManager manager = new ComremarkManager();
        public static string dizhi = "";
        CartMarager cartMarager = new CartMarager();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["sess"] == null)
                {
                    Response.Redirect("Login.aspx");
                }
                else
                {
                dizhi = "images/";
            string ddbh = Request.QueryString["ddbh"];
            Repeater1.DataSource = manager.get(ddbh);
            Repeater1.DataBind();
                userDl();
                if (Session["sessid"] != null)
                {

                   J_MiniCartNum.Text = cartMarager.CartCount((Session["sessid"].ToString())).ProPrice.ToString();//显示出购物车内物品.数量
                }  
                }
            }
        }
        public void userDl()
        {
            if (Session["sess"] != null)
            {
                //用户存在则显示出来 并且隐藏注册和登陆显示
                User user = Session["sess"] as User;
                hl_dlm.Text = "用户名:" + user.UName;
                hl_dlm.Visible = true;//显示登陆名控件
                hl_dl.Visible = false;//请登陆隐藏
                hl_zc.Visible = false;//注册隐藏
            }

        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
                string ddbh = Request.QueryString["ddbh"];
            User use = Session["sess"] as User;
            if (e.CommandName=="pl")
            {
                int id = int.Parse(Session["sessid"].ToString());
                Remark re = new Remark();
                re.Username = "1";
                re.Datenow = DateTime.Now.ToString();
                //使用循环获取textbox的值
                for (var i = 0; i < Repeater1.Items.Count; i++)
                {
                    TextBox tb = Repeater1.Items[i].FindControl("TextBox1") as TextBox;
                    if (tb != null)
                    {
                        string dd = tb.Text;
                        re.Cont = dd;
                    }
                    HiddenField hd = Repeater1.Items[i].FindControl("HiddenField1") as HiddenField;
                    if (hd!=null)
                    {
                        int sb = int.Parse(hd.Value);
                        re.Proid = sb;
                    }
                }
                re.Userid = id;
                manager.add(re);
                manager.upd(ddbh);
            }
            Response.Redirect("order.aspx");
        }
    }
}